package com.smec.remes.smecManager.SmecRetrofit.Interceptor;

import com.smec.remes.smecManager.location.SmecLocationBean;
import com.smec.remes.smecManager.location.SmecLocationManager;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by xupeizuo on 2018/3/12.
 */

public class LocationTnterceptor implements Interceptor {

    private static final String REQUEST_HEADER_DFTRACE="DF_TRACE";

    @Override
    public Response intercept(Chain chain) throws IOException {
        SmecLocationBean smecLocationBean= SmecLocationManager.getInstance().getLocationBean();

        Request request = chain.request().newBuilder()
                .addHeader(REQUEST_HEADER_DFTRACE,smecLocationBean!=null ? smecLocationBean.getLongitude()+"/"+smecLocationBean.getLatitude():"")
                .build();
        Response response = null ;
        try {
            response = chain.proceed(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }
}
